package text;

import org.junit.Test;

import java.util.Comparator;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;

public class text {
    @Test
    public void text(){
        Consumer<String> con1=new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.print(s);
            }
        };
        con1.accept("张三");
        System.out.print("**********");
        Consumer<String> con2=(s)->System.out.print(s);
        con2.accept("张三");
        Consumer<String> con3=(s)->System.out.print(s);
        con3.accept("王五");
    }
    @Test
    public void text2(){
        Comparator<Integer> com=new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return Integer.compare(o1,o2);
            }
        };
        System.out.print(com.compare(20,80));
        System.out.print("************");
        Comparator<Integer> com1=(o1,o2)->Integer.compare(o1,o2);
        System.out.print(com1.compare(20,20));

        System.out.print("************");
        Comparator<Integer> com2=Integer::compare;
        System.out.print(com2.compare(20,20));
    }
    @Test
    public void text3(){
        Function<Double,Long> fun1=new Function<Double, Long>() {
            @Override
            public Long apply(Double num) {
                return Math.round(num);
            }
        };
        System.out.print(fun1.apply(20.8));
        System.out.print("***********");
        Function<Double,Long> fun2=(num)->Math.round(num);
        System.out.print(fun2.apply(20.2));
        System.out.print("***********");
        Function<Double,Long> fun3=Math::round;
                System.out.print(fun3.apply(18.5));
    }
    @Test
    public void text4(){
        Comparator<String> com1=new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.compareTo(o2);
            }
        };
        System.out.print(com1.compare("aaa","bbb"));

        System.out.print("***********");
        Comparator<String> com2=(o1,o2)->o1.compareTo(o2);
        System.out.print(com2.compare("ccc","bb"));

        System.out.print("***********");
        Comparator<String> com3=String::compareTo;
        System.out.print(com3.compare("ccc","bb"));
    }
    @Test
    public void text5(){
        BiPredicate<String,String>bp1=new BiPredicate<String, String>() {
            @Override
            public boolean test(String s, String s2) {
                return s.equals(s2);
            }
        };
        System.out.print(bp1.test("张三","张三"));
        System.out.print("***************");
        BiPredicate<String,String>bp2=(s,s2)->s.equals(s2);
        System.out.print(bp2.test("张三","李四"));
        System.out.print("**********");
        BiPredicate<String,String>bp3=String::equals;
        System.out.print(bp3.test("张三","王五"));
    }
    @Test
    public void text6(){
        Employee employee=new Employee(1001,"小花",100.1);
        Function<Employee,String> fun1=new Function<Employee, String>() {
            @Override
            public String apply(Employee employee) {
                return employee.getEmpName();
            }
        };
        System.out.print(fun1.apply(employee));
        System.out.print("*****************");
        Function<Employee,String>fun2=(e)->e.getEmpName();
        System.out.print(fun2.apply(employee));

        System.out.print("*****************");
        Function<Employee,String>fun3=(e)->e.getEmpName();
        System.out.print(fun3.apply(employee));
    }
}
